package com.mo2323.merchant.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mo2323.common.dbo.StatPageInfo;
import com.mo2323.common.util.AjaxObject;
import com.mo2323.common.util.Page;
import com.mo2323.service.merchant.IOrderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author 高岐
 * @date 2019-01-15.
 */
@Controller
@RequestMapping("/order")
public class OrderController extends BaseController{

    @Reference
    private IOrderService orderService;


    @RequestMapping(value = "/list", method ={RequestMethod.POST, RequestMethod.GET} )
    @ResponseBody
    public AjaxObject getOrderList(@RequestParam int vid,
                                   @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                                   @RequestParam(value = "rows", defaultValue = "10", required = false) int rows) {
        try{
            Page pageDefine = new Page();
            pageDefine.setPage(page);
            pageDefine.setRows(rows);

            StatPageInfo<Map<String, Object>> pageInfo = orderService.getOrderList(vid, pageDefine);
            return AjaxObject.ok().put("data", pageInfo);
        } catch (Exception e){
            logger.error("getOrderList Exception：", e);
            return AjaxObject.error("getOrderList Exception：" + e.getMessage());
        }
    }
}
